package com.cn.mobileproject.manager;

import java.util.HashMap;

import com.cn.mobileproject.bean.Org;
import com.cn.mobileproject.bean.OrgRelation;
import com.cn.mobileproject.bean.User;
import com.cn.mobileproject.db.DaoFactory;
import com.cn.mobileproject.utils.TextHelper;

public class UserCacheManager {

	
	public static HashMap<String,User> mCache = new HashMap<String,User>();
	
	public static User getUser(String uid){
		if(mCache.containsKey(uid)){
			User user = mCache.get(uid);
			return user;
		}
		if(TextHelper.isEmpty(uid)) return null;
		User user = DaoFactory.getInstance().getUserInfoDao().searchUser(uid);
		OrgRelation or = DaoFactory.getInstance().getOrgRelationDao().searchOrgRelation(uid);
		if(or!=null&&or.orgid!=null&&!"".equals(or.orgid)){
			Org org= DaoFactory.getInstance().getOrgDao().searchOrg(or.orgid);
			if(user!=null){
				user.orgName = org.name;
				user.orgId = or.orgid;
				mCache.put(user.uid, user);
			}
		}
		return user;
	}
	
	public void clear(){
		mCache.clear();
	}
}
